﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hosting;
using Microsoft.Owin;
using Owin;
using TestSignalR;

[assembly: OwinStartup(typeof(Startup))]
namespace TestSignalR
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapConnection<TestConnection>("/SignalR", new ConnectionConfiguration()
            {
                
            });
        }
    }

    public class TestConnection : PersistentConnection
    {
        protected override bool AuthorizeRequest(IRequest request)
        {
            return false;
            //return base.AuthorizeRequest(request);
        }

        protected override IList<string> GetSignals(string userId, string connectionId)
        {
            return base.GetSignals(userId, connectionId);
        }

        protected override Task OnConnected(IRequest request, string connectionId)
        {
            return base.OnConnected(request, connectionId);
        }

        protected override Task OnDisconnected(IRequest request, string connectionId, bool stopCalled)
        {
            return base.OnDisconnected(request, connectionId, stopCalled);
        }

        protected override Task OnReconnected(IRequest request, string connectionId)
        {
            return base.OnReconnected(request, connectionId);
        }

        protected override Task OnReceived(IRequest request, string connectionId, string data)
        {
            return Connection.Broadcast(data);
            //return base.OnReceived(request, connectionId, data);
        }

        protected override IList<string> OnRejoiningGroups(IRequest request, IList<string> groups, string connectionId)
        {
            return base.OnRejoiningGroups(request, groups, connectionId);
        }

        public override Task ProcessRequest(HostContext context)
        {
            return base.ProcessRequest(context);
        }

        public override void Initialize(IDependencyResolver resolver)
        {
            base.Initialize(resolver);
        }
    }
}